<?php
class SlingApp extends MemberbaseApp
{
	var $_sling_mod;
	
	function __construct(){
		parent::__construct();
		$this->SlingApp();
	}
	
	function SlingApp(){
		$this->_sling_mod=&m('sling');
	}
	
	//挂绳列表
	function index(){
		$page = $this->_get_page();
		$sling_list = $this->_sling_mod->find(array(
				'conditions' => 'if_show=1',
				'count' => true,
				'limit' => $page['limit']
		));
		$page['item_count'] = $this->_sling_mod->getCount();
		$this->_format_page($page);
		$this->assign('page_info', $page);
		$this->assign('sling_list', $sling_list);
		$this->display('sling.index.html');
		$this->_curlocal(Lang::get('sling_list'));
	}
	
	//添加挂绳位置
	function add(){
		if(!$_POST){
			$this->_curlocal(Lang::get('sling_list'), 'index.php?app=sling&act=index',
					Lang::get('add_sling'));
			$this->display('sling.form.html');
		}else{
			$data=array();
			$sling_position=trim($_POST['sling_position']);
			if (!$sling_position){
				$this->show_warning('sling_position_not_empty');
				return;
			}
			$data['sling_position']=$sling_position;
			$this->_sling_mod->add($data);
			if ($this->_sling_mod->has_error()){
				$this->show_warning($this->_sling_mod->get_error());
				return;
			}
			$this->show_message('添加成功',Lang::get('sling_list'),'index.php?app=sling&act=index');
		}
	}
	
	
	function edit(){
		$sling_id=isset($_GET['sling_id'])?$_GET['sling_id']:0;
		if (!$sling_id){
			$this->show_warning("没有该挂绳位置");
			return;
		}
		if(!$_POST){
			$sling_info=$this->_sling_mod->get($sling_id);
			$this->_curlocal(Lang::get('sling_list'), 'index.php?app=sling&act=index',
					Lang::get('edit_sling'));
			$this->assign('sling',$sling_info);
			$this->display('sling.form.html');
		}else{
			$data=array();
			$sling_position=trim($_POST['sling_position']);
			if (!$sling_position){
				$this->show_warning('sling_position_not_empty');
				return;
			}
			$data['sling_position']=$sling_position;
			$this->_sling_mod->edit($sling_id,$data);
			if ($this->_sling_mod->has_error()){
				$this->show_warning($this->_sling_mod->get_error());
				return;
			}
			$this->show_message('编辑成功',Lang::get('sling_list'),'index.php?app=sling&act=index');
		}
	}
	
	
	function drop(){
		$sling_id=isset($_GET['sling_id'])?$_GET['sling_id']:0;
		if (!$sling_id){
			$this->show_warning("没有该挂绳位置");
			return;
		}
		$this->_sling_mod->drop($sling_id);
		if ($this->_sling_mod->has_error()){
			$this->show_warning($this->_sling_mod->get_error());
			return;
		}
		$this->show_message('删除成功');
	}
}